﻿using HDUSampling.HDUControls.HTools.LoadingFrm;
using HMI.Model;
using HMI.Tool;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Forms;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using WLMes.Models;

namespace HMI.View.OrderFrmTools
{
    /// <summary>
    /// OrderList.xaml 的交互逻辑
    /// </summary>
    public partial class OrderList : System.Windows.Controls.UserControl
    {
        public OrderList()
        {
            InitializeComponent();         
            this.DataContext = new OrderListViewModel();
        }
        ProcessInfoVO ProcessInfo =null;
        public Action<string, string> ViewTasksets { get; set; }
        public Action<string> ViewMats { get; set; }
        private void daye_SelectedCellsChanged(object sender, SelectedCellsChangedEventArgs e)
        {
            // 检查是否有新的选中项
            if (dg.SelectedItem != null)
            {
                // 获取选中项的数据上下文（即绑定的数据项）
                ProcessInfoVO selectedItem = dg.SelectedItem as ProcessInfoVO;
                if (selectedItem != null)
                {
                    //List<ParameterSets> parameterSets = SuSql.db.Queryable<ParameterSets>()
                    //.Where(t => t.ParameterSets_ID == selectedItem.ParameterSets_ID).ToList();
                    // 现在您可以使用 selectedItem 变量进行操作
                    // 例如，显示一个消息框
                    //string var= JsonConvert.SerializeObject(selectedItem);
                    //MessageBox.Show($"选中的项的 ID 是: {selectedItem.TaskSets_ID}");
                    ProcessInfo = selectedItem;
                }
            }
        }
        public void DeleteBtn(object sender, RoutedEventArgs e)
        {
            string Batch_ID = ProcessInfo.ProcessInfo_ID;
            string Batch_Code = ProcessInfo.ProductionBatchCode;
            if (ViewTasksets != null) {
                if (Batch_Code.Contains("MUN")) { 
                
                } 
                else {
                    Msgbox.ShowCenter(this, "系统消息", "MES任务，无法删除！改单任务MES接口下发，EventCode=86", null);
                }
            }
        }

        private void Task_Button_Click(object sender, RoutedEventArgs e)
        {
            ViewTasksets(ProcessInfo.TaskSets_ID,ProcessInfo.ProductionBatchCode);
        }

        public void ViewMatBtn(object sender, RoutedEventArgs e) {
            ViewMats(ProcessInfo.BoardMaterialSets_ID);
        }

    }
}
